/****** Object:  Stored Procedure dbo.CGO_AccountAdd    Script Date: Monday, March 07, 2011 ******/
IF EXISTS ( SELECT  *
            FROM    dbo.sysobjects
            WHERE   id = OBJECT_ID(N'dbo.CGO_AccountSave')
                    AND OBJECTPROPERTY(id, N'IsProcedure') = 1 ) 
  DROP PROCEDURE dbo.CGO_AccountSave
GO

/* -------------------------------------------------------------------------------------
/   AccountAdd
/  ------------------------------------------------------------------------------------- */
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE dbo.CGO_AccountSave  
  @PortalID INT ,
  @UserID INT ,
  @Token MONEY  
AS 
  DECLARE @TokenBefore MONEY , @TokenAfter MONEY  
  IF EXISTS ( SELECT  1
              FROM    dbo.CGO_Account
              WHERE   PortalID = @PortalID
                      AND UserID = @UserID ) 
    BEGIN      
      UPDATE  dbo.CGO_Account
      SET     Token = @Token ,
              LastUpdateDate = GETDATE()
      WHERE   PortalID = @PortalID
              AND UserID = @UserID            
    END
  ELSE 
    BEGIN
      INSERT  INTO dbo.CGO_Account
              ( UserID ,
                PortalID ,
                Token ,
                LastUpdateDate 
              )
      VALUES  ( @UserID ,
                @PortalID ,
                @Token ,
                GETDATE()
              )           
    END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
